#include <cstdio>

using namespace std;

const int maxn = 400, maxm = maxn * (maxn - 1) / 2;

int min(int a, int b) { return a < b ? a : b; }

class Graph {
public:
  int m, ind[maxn + 1], to[2 * maxm + 1], id[2 * maxm + 1], link[2 * maxm + 1],
      dis[maxn + 1];

  void addSide(int u, int v, int w) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
    id[m] = w;
  }

  void spfa(int s) {
    static int que[maxn + 1];
    static bool book[maxn + 1];
    for (int i = 1; i <= maxn; i++)
      dis[i] = 0x7ffffff;

    int h = 0, t = 1;
    que[1] = s, book[s] = true, dis[s] = 0;
    for (; h != t;) {
      h = h % maxn + 1;
      int x = que[h];
      book[x] = false;
      for (int i = ind[x]; i; i = link[i]) {
        int y = to[i];
        if (dis[y] > dis[x] + 1) {
          dis[y] = dis[x] + 1;
          if (!book[y]) {
            book[y] = true;
            t = t % maxn + 1;
            que[t] = y;
          }
        }
      }
    }
  }
};

int main() {
  freopen("graph.in", "r", stdin);
  freopen("graph.out", "w", stdout);

  static Graph g;
  int n, m, s, t;
  scanf("%d %d %d %d", &n, &m, &s, &t);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g.addSide(u, v, i);
    g.addSide(v, u, i);
  }
  g.spfa(s);

  static int ans[maxm + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = g.ind[i]; j; j = g.link[j]) {
      ans[g.id[j]] = min(min(g.dis[i], g.dis[g.to[j]]) + 1, g.dis[t]);
    }
  }

  printf("%d\n", g.dis[t]);
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
